package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.vo.ImageQueueTaskVO;
import com.fdb.efp.nls.service.dao.ImageQueueTaskDao;
import com.fdb.efp.nls.service.domain.ImageQueueTask;
import com.fdb.efp.nls.service.facade.ImageQueueTaskService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 影像任务队列				<p>
 * @author ligm
 * @date 2019-01-03
 */
@Service("imageQueueTaskService")
public class ImageQueueTaskServiceImpl implements ImageQueueTaskService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(ImageQueueTaskServiceImpl.class);

	@Autowired
	private ImageQueueTaskDao imageQueueTaskDao;
	
	/**
	 * 新增操作
	 */
	public int insertImageQueueTask(ImageQueueTaskVO inImageQueueTaskVo) {
		logger.debug("当前新增数据为:"+ inImageQueueTaskVo.toString());
		int num = 0;
		try {
			ImageQueueTask imageQueueTask = new ImageQueueTask();
			beanCopy(inImageQueueTaskVo, imageQueueTask);
			num = imageQueueTaskDao.insertImageQueueTask(imageQueueTask);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(ImageQueueTaskVO inImageQueueTaskVo) {
		logger.debug("当前删除数据条件为:"+ inImageQueueTaskVo);
		int num = 0;
		try {
			ImageQueueTask imageQueueTask = new ImageQueueTask();
			beanCopy(inImageQueueTaskVo, imageQueueTask);
			num = imageQueueTaskDao.deleteByPk(imageQueueTask);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inImageQueueTaskVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(ImageQueueTaskVO inImageQueueTaskVo) {
		logger.debug("当前修改数据为:"+ inImageQueueTaskVo.toString());
		int num = 0;
		try {
			ImageQueueTask imageQueueTask = new ImageQueueTask();
			beanCopy(inImageQueueTaskVo, imageQueueTask);
			num = imageQueueTaskDao.updateByPk(imageQueueTask);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inImageQueueTaskVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public ImageQueueTaskVO queryByPk(ImageQueueTaskVO inImageQueueTaskVo) {
		
		logger.debug("当前查询参数信息为:"+ inImageQueueTaskVo);
		try {
			ImageQueueTask queryImageQueueTask = new ImageQueueTask();
			beanCopy(inImageQueueTaskVo, queryImageQueueTask);
			ImageQueueTask queryRslImageQueueTask = imageQueueTaskDao.queryByPk(queryImageQueueTask);
			if (Objects.nonNull(queryRslImageQueueTask)) {
				ImageQueueTaskVO outImageQueueTaskVo = beanCopy(queryRslImageQueueTask, new ImageQueueTaskVO());
				logger.debug("当前查询结果为:"+ outImageQueueTaskVo.toString());
				return outImageQueueTaskVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ImageQueueTaskVO> queryAllOwner(ImageQueueTaskVO imageQueueTaskVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<ImageQueueTaskVO> list = null;
		try {
			List<ImageQueueTask> imageQueueTasks = imageQueueTaskDao.queryAllOwnerByPage(imageQueueTaskVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ imageQueueTasks.size());
			pageSet(imageQueueTasks, imageQueueTaskVo);
			list = (List<ImageQueueTaskVO>) beansCopy(imageQueueTasks, ImageQueueTaskVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ImageQueueTaskVO> queryAllCurrOrg(ImageQueueTaskVO imageQueueTaskVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<ImageQueueTask> imageQueueTasks = imageQueueTaskDao.queryAllCurrOrgByPage(imageQueueTaskVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+imageQueueTasks.size());
		List<ImageQueueTaskVO> list = null;
		try {
			pageSet(imageQueueTasks, imageQueueTaskVo);
			list = (List<ImageQueueTaskVO>) beansCopy(imageQueueTasks, ImageQueueTaskVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<ImageQueueTaskVO> queryAllCurrDownOrg(ImageQueueTaskVO imageQueueTaskVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<ImageQueueTask> imageQueueTasks = imageQueueTaskDao.queryAllCurrDownOrgByPage(imageQueueTaskVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ imageQueueTasks.size());
		List<ImageQueueTaskVO> list = null;
		try {
			pageSet(imageQueueTasks, imageQueueTaskVo);
			list = (List<ImageQueueTaskVO>) beansCopy(imageQueueTasks, ImageQueueTaskVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
